package org.example.Polls;

import java.io.File;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;

public class SettingsActivity extends PreferenceActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		addPreferencesFromResource(R.xml.preferences);
		
		// Get the custom preference
		Preference customPref = (Preference) findPreference("deleteInternalStorage");
		customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			public boolean onPreferenceClick(Preference preference) {
                // delete user for debugging
                File dir = getFilesDir();
                File file = new File(dir, MainMenuActivity.CONFIG_FILE);
                boolean deleted = file.delete();
                
                // Display a message to the user
                String msg = null;
                if (deleted) {
                	msg = "The internal storage file has been deleted";
                } else {
                	msg = "Failed to delete the internal storage file";
                }
    			Toast.makeText(getBaseContext(), msg,  Toast.LENGTH_LONG).show();
				
				return true;
			}
		});
	}
}